home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 12.4 KB | 320 lines | [TEXT/MPS ] |
- // UMenuMgr.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UMENUMGR__
- #define __UMENUMGR__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __ULISTITERATOR__
- #include "UListIterator.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- // Toolbox
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Constants
- //----------------------------------------------------------------------------------------
-
- const ResNumber mFirstMenu = 1; // MacApp manages menu titles
- // mFirstMenu..mLastMenu generically
-
- const ResNumber mApple = mFirstMenu; // MacApp does not disable any commands in
- // this menu
-
- const ResNumber mFile = mApple + 1; // Default ID of the File menu
-
- const ResNumber mEdit = mFile + 1; // Default ID of the Edit menu
-
- const ResNumber mDocument = 20; // Document Menu
-
- const ResNumber mOpenDocEdit = 21; // Edit Menu with OpenDoc items
-
- const ResNumber mEditionMgrEdit = 30; // Edit Menu with Edition Mgr support
-
- const ResNumber mMail = 31; // Default ID of the Mail menu
-
- const ResNumber mDebug = 900; // read in if debugging is turned on;
- // number corresponds with debugging
- // command numbers
-
- const ResNumber mDebugFlags = 127; // read in if debugging is turned on;
- // number corresponds with debugging
- // command numbers
-
- const ResNumber mDebugFont = mDebugFlags - 1; // read in if debugging is turned on;
- // number corresponds with debugging
- // command numbers
-
- const ResNumber mDebugSize = mDebugFont - 1; // read in if debugging is turned on;
- // number corresponds with debugging
- // command numbers
-
- const ResNumber mLastMenu = 63; // MacApp disables menu titles
- // mFile..mLastMenu generically
-
- class TMenuBarManager : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- ResNumber fDisplayedMenus;
- ResNumber fPreferredMenuBarID;
-
- ResNumber fDisplayedHierMenus;
- ResNumber fPreferredHierMenuBarID;
- #if qContainer
- Handle fAppMenuBar;
- #endif
- inline TMenuBarManager()
- { }
- // Empty constructor
-
- virtual ~TMenuBarManager();
- // Destructor
-
- void IMenuBarManager( ResNumber otherMenus );
- // Initialize the object
-
- virtual void Reset ();
- // Called to indicate that there is no preferred menu bar
-
- virtual void SetPreferredMenuBarID (ResNumber theID);
- // Called to indicate a preference for a menu bar
-
- virtual void SetPreferredHierMenuBarID ( ResNumber theID );
- // Called to indicate a preference for a hierarchical menu bar
-
- virtual ResNumber GetPreferredMenuBarID ();
- // Returns the ID of the preferred menu bar
-
- virtual ResNumber GetPreferredHierMenuBarID ();
- // Returns the ID of the preferred hierarchical menu bar
-
- virtual void InstallPreferredMenus ();
- // Called to actually install the preferred menus in the menu bar.
-
- virtual void AddHelpMenuItem( CStr255 helpText, CommandNumber helpCommand );
- // Adds a help item to System 7's help menu (if available). If 'helpText'
- // contains the string '^0', the application name is substituted.
- // helpText should almost always be "^0 Help" or "^0 Shortcuts"
-
- virtual void AddMenuItem(const CStr255& theMenuItemText,
- MenuID menuNumber,
- short insertAfterItem,
- CommandNumber theMenuItemCommandNumber);
- // Adds a menu item to the specified menu
-
- virtual void DeleteMenuItem(CommandNumber theMenuItemCommandNumber);
- // Deletes the menu item that is specified by the command number
- };
-
- //----------------------------------------------------------------------------------------
- // CMenuIterator: A simple iterator for menu lists.
- //----------------------------------------------------------------------------------------
-
- class CMenuIterator : public CHandleIterator
- {
-
- public:
- CMenuIterator();
-
- virtual ~CMenuIterator();
-
- inline MenuRef CurrentMenu()
- { return (MenuRef)CurrentHandle(); }
- // returns the current window
-
- inline MenuRef FirstMenu()
- { return (MenuRef)FirstHandle(); }
- // Resets the iterator to begin again and returns the first window in the window list
-
- inline MenuRef NextMenu()
- { return (MenuRef)NextHandle(); }
- // increments and then returns the window in the window list
-
- protected:
- virtual void Advance(); // override
- // Advances the iteration
-
- };
-
- //----------------------------------------------------------------------------------------
- // typedefs for procedural parameter types.
- //----------------------------------------------------------------------------------------
-
- typedef void (*MenuSetupType) (void* yourDataPtr);
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations.
- //----------------------------------------------------------------------------------------
-
- extern TMenuBarManager* gMenuBarManager;
- // Used to manage the installation of preferred menu bars.
-
- #if qDebug
- extern Boolean gTraceSetupMenus;
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations: The following routines all recognize command numbers of
- // the form -(256 * menu + item) and -(256 * menu). The former is used when there is no
- // command number; the latter to enable/ disable a whole menu (rare)
- //----------------------------------------------------------------------------------------
-
- Boolean CommandEnabled(CommandNumber command);
- // Returns true if the given command is currently enabled.
-
- CommandNumber CommandFromMenuItem(short menu, short item);
- // Returns the command number for the given menu ID and item number. If the item
- // number is positive, the command table is search for the given menu/ item pair. If
- // found, the corresponding command number is returned. If not found, the number
- // returned is equal to -(256 * menu + item). If the item number is negative, the
- // number returned is equal to -item number.
-
- void CommandToMenuItem(CommandNumber aCommand, short& menu, short& item);
- // CommandToMenuItem returns the menu ID and item number of the given command. If
- // aCommand is positive, the command table is searched for aCommand. If it is found,
- // CommandToMenuItem returns the corresponding menu ID and item number. Otherwise menu
- // and item are set to zero. If aCommand is negative, the menu number is the upper
- // eight bits, and the item number the lower eight bits, of the absolute value of
- // aCommand. (This implies that menu id's must be <= 127 and item numbers must be
- // <= 255.)
-
- MenuRef CommandToComponents(CommandNumber command, MenuID& menuNo, short& itemNo);
- // CommandToComponents returns the menu ID and item number of the given command. as
- // well as the MenuRef if the command exists.Otherwise it returns nil.
-
- void CommandToName(CommandNumber aCommand, CStr255& menuText);
- // Return the text of the menu item for the given command.
-
- void Enable(CommandNumber aCommand, Boolean canDo);
- // Enable or disable a command
-
- void EnableCheck(CommandNumber aCommand, Boolean canDo, Boolean checkIt);
- // Enable/ Disable and check/ uncheck a command
-
- MenuRef GetResMenu(ResNumber menuResID);
- // Utility that just does GetResource('MENU', resourceID), so that it works for menus
- // not currently in the menu bar. (You cannot call GetMenu more than once for the same
- // menu, so you can use this (or MAGetMenu which is preferred) instead.)
-
- void AddMenuBar(ResNumber itsID, Boolean isHierarchical);
- // Add all the menus in the menu bar to the applications menus. Note that hierarchical
- // must be treated differently from regular menus in that they are added with
- // InsertMenu(, -1). We can't use GetNewMBar here because we want to call MAGetMenu
- // for each menu in the MBAR, and GetNewMBar would not do that for us.
-
- MenuRef GetIndMenu(ResNumber itsID, ResNumber itsIndex);
- // Return a menu handle to the Nth menu in a menu bar.
-
- short CountMenus(ResNumber itsID);
- // Returns the number of menus in a menu bar.
-
- MenuRef ConvertToMenu(Handle CMNUHandle);
-
- void InitUMenuMgr();
- // Initializes this unit, and must be called before using any other part of this unit.
- // Loads the command table and sets up the NULL menu proc.
-
- Boolean IsManagedMenu(MenuRef theMenu);
- // given a MenuRef, this function returns true if it is a managed menu in our menu
- // handle table
-
- Handle MAGetNewMBar(ResNumber menuRsrcID);
- // Equivalent to the Menu Manager's GetNewMBar except it explicitly sets the menu
- // bar's colors.
-
- void MAInsertInMenuTable( MenuRef theMenu, ResNumber menuResID );
- // Inserts theMenu in the private gMenuTable.
-
- void MAInsertMenu(MenuRef theMenu, ResNumber menuResID, MenuID beforeID);
- // Equivalent to the Menu Manager's InsertMenu with the addition that the MAInsertMenu
- // looks for an 'mctb' resource whose id is the menu's id (as specified by menuResID),
- // and if it is present applies the 'mctb' to the menu.
-
- MenuRef MAGetMenuRef(MenuID menuID);
- // Similar to GetMHandle, but also checks the global menu table list
-
- MenuRef MAGetMenu(ResNumber menuResID);
- // Not quite equivalent to GetMenu because it doesn't load the menuDefProc or color
- // table yet. It does, however, let you get the MenuRef without calling GetMenu
- // more than once.It tries the menubar first and then calls GetResMenu if necessary.
-
- void NeedCalcMenuSize(MenuRef aMenuRef);
- // This procedure is called as part of the menu setup process and indicates that the
- // given menu needs CalcMenuSize. You must explicitly call this if you use change a
- // menu by means other than those supplied in this unit (e.g. you insert or delete
- // items from a menu). Failure to do so will result in improperly sized menus.
-
- void SetCommandIcon(CommandNumber aCommand, Byte menuIcon);
- // You should call this (instead of the Toolbox's SetCommandIcon) for menus that are
- // in the range [1..mLastMenu]. In addition to changing the menu this tells MacApp
- // that the menu's size needs to be recomputed.
-
- void SetCommandName(CommandNumber aCommand, const CStr255& menuText);
- // You should call this (instead of the Toolbox's SetItem) for menus that are in the
- // range [1..mLastMenu]. In addition to changing the menu this tells MacApp that the
- // menu's size needs to be recomputed.
-
- void SetIndividualCommandName(CommandNumber aCommand, ResNumber rsrcID, short strIndex);
- // Does a GetIndString with the rsrcID & strIndex; and then a SetCommandName.
-
- void SetMenuState(CommandNumber aCommand,
- ResNumber rsrcID,
- short falseBuzzItem,
- short trueBuzzItem,
- Boolean stateVariable);
- // IF stateVariable THEN
- // SetIndividualCommandName(aCommand, rsrcID, trueBuzzItem)
- // ELSE
- // SetIndividualCommandName(aCommand, rsrcID, falseBuzzItem);
-
- void SetStyle(CommandNumber aCommand, /* Style */ short aStyle);
- // You should call this (instead of the Toolbox's SetItemStyle) for menus that are in
- // the range [1..mLastMenu]. In addition to changing the menu this tells MacApp that
- // the menu's size needs to be recomputed.
-
- void PerformMenuSetup(MenuSetupType TheMenuSetterUpper,
- void* yourDataPtr);
- // Routine that perfoms the menu setup.
-
- void InvalidateMenus();
- // Invalidate all the items on all the menus. Just like invalidation for windows it
- // doesn't immediately change the visual appearance when you invalidate, it just means
- // they are invalid and should be "setup" before showing them to the user again.
-
- void ValidateMenus();
- // Validate all the items on all the menus. Just like Validation for windows it
- // doesn't immediately change the visual appearance when you Validate, it just means
- // they don't need to be changed before showing them to the user again.
-
- Boolean MenusHavePendingUpdate();
- // True if the menus are invalid and should be "setup" before showing them to the
- // user.
-
- void InvalidateMenuBar();
- // Invalidate the menu bar. It should be redrawn again.
-
- void MAHiliteMenu(short menuID);
- // Just like the toolbox call HiliteMenu only avoids calling HiliteMenu if possible
- // This saves an astonishing amount of CPU time.
- #endif
-
-
-